<?php
namespace App\Http\Controllers\Admin;

use App\Services\Admin\AdminService;
use Illuminate\Http\Request;

class AdminController extends BaseController
{
    public function __construct(AdminService $service)
    {
        $this->db = $service;
    }

    /**
     * 列表
     */
    public function getIndex(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
//        $headers = $this->getAid($request);
//        if ($headers['code'] != 0) {
//            return $this->toJson(-2, $headers['msg']);
//        }
        $pages['start'] = $request->get('pageStart', 0);
        $pages['limit'] = $request->get('pageLimit', 10);
        $res = $this->db->getIndex($pages);
        if ($res['code']!=0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //修改
    public function modify(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
//        $headers = $this->getAid($request);
//        if ($headers['code'] != 0) {
//            return $this->toJson(-2, $headers['msg']);
//        }
        $id = $request->post('id', 0);
        $pas['name'] = $request->post('title', '');
        $res = $this->db->modify($id, $pas);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

//    //删除
//    public function del(Request $request)
//    {
//        //header('Access-Control-Allow-Origin: *');
////        $headers = $this->getAid($request);
////        if ($headers['code'] != 0) {
////            return $this->toJson(-2, $headers['msg']);
////        }
//        $id = $request->post('id', 0);
//        $res = $this->db->del($id);
//        if ($res['code']!=0) {
//            return $this->toJson(-2, $res['msg']);
//        }
//        return $this->toJson();
//    }
}